$('#title').html('还款计划');
var param = vipspa.getMessage('msg_cardlist'); //银行卡列表参数
var msg_calend = vipspa.getMessage('msg_calend'); //日历页面参数

//接收银行卡列表传来的参数，并做相关缓存
if(JSON.stringify(param) != "{}"){
	$('#setplan-bankname').html(param.content.bankName);
	$('#setplan-bankNo').html(param.content.cardNo);
	$('.setplan-banklogo').children('img').attr('src',param.content.bankLogo);
	$('#startDate').html(sessionStorage.startDate);
    $('#endDate').html(sessionStorage.endDate);
    //将银行卡数据做缓存
    sessionStorage.bankName = param.content.bankName, //银行名称
    sessionStorage.bankCardId = param.content.bankCardId; //银行卡id
    sessionStorage.bankLogo = param.content.bankLogo; //银行卡logo
    sessionStorage.cardNo = param.content.cardNo; //银行卡号
 	sessionStorage.isOpenQuick = param.content.isOpenQuick; //是否开通快捷
 	sessionStorage.phoneNo = param.content.phoneNo; //缓存预留手机号
}else{
	$('#setplan-bankname').html(sessionStorage.bankName);
	$('#setplan-bankNo').html(sessionStorage.cardNo);
	$('.setplan-banklogo').children('img').attr('src',sessionStorage.bankLogo);
	$('#startDate').html(sessionStorage.startDate);
    $('#endDate').html(sessionStorage.endDate);
}

//渲染还款日期
if(JSON.stringify(msg_calend) != "{}"){
	$('#reDates').val(msg_calend.content.DateArrString);
	$('#DateText').html(msg_calend.content.DateTextArr);
	sessionStorage.orderId = 1;
}

if(sessionStorage.orderId == 0){
		$('.setorderdbox').show();
}

//确认账单日还款日后，点击确认(model框内容)
$('#setplan-setorderday').click(function(){
	let startDate = $('#setplan-statement').val();
	let endDate = $('#setplan-repay').val();
	if(startDate == '' || endDate == ''){
		layer.open({content: '账单日/还款日不能为空' ,skin: 'msg',time: 2});
	}else{
		Cardlist.setOrderConf({
			method:'creditcard.conf',
			version: '1.0.2',
			userId: localStorage.rpUserId,
			bundCardId: sessionStorage.bankCardId,
			startDate: startDate,
			endDate: endDate
		},function(){
			$('#startDate').text(startDate);
			$('#endDate').text(endDate);
			sessionStorage.endDate = endDate;
			sessionStorage.startDate = startDate;
			sessionStorage.orderId = 1;
		});
	}
});

//点击修改账单日还款日
$('.setplan-banner').click(function(){
	$('.setorderdbox').show();
	if(sessionStorage.orderId != 0){ //非第一次绑定还款日，可关闭model框
		$('.setorderdbox').click(function(){
			$(this).hide();
		});
	}
});

//设置还款日历
$('.setplan-date').click(function(){
	location.hash = 'calendar';
});


//完成计划设置，进入预览页面
$('.confirm').click(function(){
	let totalAmont = $('#totalAmont').val();
	let reDates = $('#reDates').val();
	sessionStorage.DateText = $('#DateText').text();
	if(totalAmont != '' && reDates != ''){
		sessionStorage.reDates = reDates;
		sessionStorage.totalAmont = totalAmont*100;
		Cardlist.generationPlan({
			method:'plan.preview',
			version: '1.0.2',
			userId: localStorage.rpUserId,
			bundCardId: sessionStorage.bankCardId,
			reDates: sessionStorage.reDates,
			totalAmount: sessionStorage.totalAmont
		},function(res){
			location.hash = 'details';
		})
	}else{
		layer.open({content: '账单金额/还款日期不能为空' ,skin: 'msg',time: 2});
	}
});


